﻿using MyOrder;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsList
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 查询数据库IP，流水号，检验次数等信息是否完善
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //获取当前数据库
            var strcon = textBox1.Text.Trim();

            //测试是否连接到了服务器
            SqlConnectionLianJie.lianjieStr = strcon;
            if (SqlConnectionLianJie.GetConnection() == "1")
            {
                MessageBox.Show("服务器连接错误");
                return;
            }

            //获取要查询信息的流水号
            var listNumber = textBox2.Text.Trim();
            if (listNumber == "")
            {
                MessageBox.Show("请输入流水号");
                return;
            }
            //获取检验次数
            int listCount=0;
            if (textBox4.Text.Trim() == "")
            {
                MessageBox.Show("请输入检验次数");
                return;
            }
            else
            {
                listCount = int.Parse(textBox4.Text.Trim());
            }
            //获取尾气类型
            var eType = selectCobox.Text;

            //连接数据库查询对应信息
            //string sqlStr = "SELECT [lsh] ,[jycs] ,[xh] ,[mc] ,[jyjg] ,[jybz] ,[pd] FROM [Veh_Comprehensive].[dbo].[Z_JYBG] where lsh = @ls and jycs = @cs";
            DataSet dataset=SqlHelper.ExecuteDataSet("SELECT * FROM [Veh_Comprehensive].[dbo].[Z_veh_data] where [流水号] = @ls and [检验次数] = @cs",
                new SqlParameter("@ls", listNumber),
                new SqlParameter("@cs", listCount));

            DataTable dt = dataset.Tables[0];
            //判断是否查到数据
            if (dt.Rows.Count <= 0)
            {
                MessageBox.Show("查无此号");
            }
            else
            {
                MessageBox.Show("OK");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            initForm();
        }
        /// <summary>
        /// 页面加载
        /// </summary>
        private void initForm()
        {
            //List<string> listStr = new List<string>();
            //listStr.Add("合格");
            //listStr.Add("不合格");

            //尾气类型初始化
            selectCobox.Items.Clear();
            selectCobox.Items.Add("双怠速");
            selectCobox.Items.Add("简易瞬态");
            selectCobox.Items.Add("自由加速");
            selectCobox.Items.Add("加载减速");
            selectCobox.SelectedIndex = 0;

            #region 排放性双怠速高怠速
            sdCobox2.Items.Clear();
            sdCobox2.Items.Add("合格");
            sdCobox2.Items.Add("不合格");
            sdCobox2.SelectedIndex = 0;

            sdCobox3.Items.Clear();
            sdCobox3.Items.Add("合格");
            sdCobox3.Items.Add("不合格");
            sdCobox3.SelectedIndex = 0;

            sdCobox4.Items.Clear();
            sdCobox4.Items.Add("合格");
            sdCobox4.Items.Add("不合格");
            sdCobox4.SelectedIndex = 0;

            sdCobox5.Items.Clear();
            sdCobox5.Items.Add("合格");
            sdCobox5.Items.Add("不合格");
            sdCobox5.SelectedIndex = 0;

            sdCobox6.Items.Clear();
            sdCobox6.Items.Add("合格");
            sdCobox6.Items.Add("不合格");
            sdCobox6.SelectedIndex = 0;
            #endregion

            #region 排放性简易瞬态工况
            jyCobox7.Items.Clear();
            jyCobox7.Items.Add("合格");
            jyCobox7.Items.Add("不合格");
            jyCobox7.SelectedIndex = 0;

            jyCobox8.Items.Clear();
            jyCobox8.Items.Add("合格");
            jyCobox8.Items.Add("不合格");
            jyCobox8.SelectedIndex = 0;

            jyCobox9.Items.Clear();
            jyCobox9.Items.Add("合格");
            jyCobox9.Items.Add("不合格");
            jyCobox9.SelectedIndex = 0;

            jyCobox10.Items.Clear();
            jyCobox10.Items.Add("合格");
            jyCobox10.Items.Add("不合格");
            jyCobox10.SelectedIndex = 0;

            #endregion

            #region 排放性自由加速法光吸收系数
            upCobox11.Items.Clear();
            upCobox11.Items.Add("合格");
            upCobox11.Items.Add("不合格");
            upCobox11.SelectedIndex = 0;
            #endregion

            #region 排放性加载减速工况光吸收系数
            downCobox12.Items.Clear();
            downCobox12.Items.Add("合格");
            downCobox12.Items.Add("不合格");
            downCobox12.SelectedIndex = 0;

            downCobox13.Items.Clear();
            downCobox13.Items.Add("合格");
            downCobox13.Items.Add("不合格");
            downCobox13.SelectedIndex = 0;

            downCobox14.Items.Clear();
            downCobox14.Items.Add("合格");
            downCobox14.Items.Add("不合格");
            downCobox14.SelectedIndex = 0;

            downCobox15.Items.Clear();
            downCobox15.Items.Add("合格");
            downCobox15.Items.Add("不合格");
            downCobox15.SelectedIndex = 0;

            #endregion

            #region 总判定
            zcomboBox16.Items.Clear();
            zcomboBox16.Items.Add("O");
            zcomboBox16.Items.Add("X");           
            zcomboBox16.SelectedIndex = 0; 
            #endregion

            foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                   // c.Text = "";
                }
            }
            //\b是特殊字符需要转义
           // textBox1.Text = @"127.0.0.1\bhsql";
            textBox3.Text = "≤ ≥＜＞ ±";
            textBox36.Text = "总判定";

            //判定标准值
            //双怠速
            sdtextBox10.Text = "＜0.30";
            sdtextBox11.Text = "＜50";
            sdtextBox12.Text = "1.05-0.95";
            sdtextBox13.Text= "＜0.60";
            sdtextBox14.Text= "＜80";

            //简易瞬态
            jytextBox19.Text = "＜8.00";
            jytextBox18.Text = "＜1.60";
            jytextBox17.Text = "＜1.30";


            //自由加速光吸收率
            uptextBox27.Text = "＜1.20";

            //加载减速光吸收系数
            downtextBox32.Text= "＜1.20";
            downtextBox33.Text = "＜1.20";
            downtextBox34.Text = "＜1.20";
            downtextBox35.Text = "≥";
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //获取数据库地址连接数据库
            var strcon = textBox1.Text.Trim();
            SqlConnectionLianJie.lianjieStr = strcon;
            //获取要查询信息的流水号
            var listNumber = textBox2.Text.Trim();
            //获取检验次数
            var listCount = int.Parse(textBox4.Text.Trim());

            //提示信息
            string liststr = "";

            DeleteJYBG(listNumber, 41, 61);
          
            //拿到尾气类型
            var gasType=selectCobox.Text;
            if (gasType == "双怠速")
            {
                #region 双怠速信息录入错误方法已经注释（因为没有录入null值的数据）
                ////清除Z_JYBG表里对应的相关数据
                //DeleteJYBG(listNumber, 41, 45);
                ////拿到双怠速输入的值
                //Z_veh_data zDate = new Z_veh_data();
                //zDate.SDCO = float.Parse(decideTxt(sdtextBox5.Text.Trim()));
                //zDate.SDHC = float.Parse(decideTxt(sdtextBox6.Text.Trim()));
                //zDate.SDRo = float.Parse(decideTxt(sdtextBox7.Text.Trim()));
                //zDate.SDCOCO = float.Parse(decideTxt(sdtextBox8.Text.Trim()));
                //zDate.SDHCHC = float.Parse(decideTxt(sdtextBox9.Text.Trim()));
                ////录入数据(表Z_veh_data)
                //var sj = SqlHelper.ExecuteNonQuery("update [Veh_Comprehensive].[dbo].[Z_veh_data]set[排放性双怠速高怠速CO] =@SDCO,[排放性双怠速高怠速HC] =@SDHC,[排放性双怠速高怠速λ] =@SDRo,[排放性双怠速低怠速CO] =@SDCOCO,[排放性双怠速低怠速HC] =@SDHCHC where[流水号] =@ls and[检验次数] = @cs",
                //    new SqlParameter("@SDCO", zDate.SDCO),
                //    new SqlParameter("@SDHC", zDate.SDHC),
                //    new SqlParameter("@SDRo", zDate.SDRo),
                //    new SqlParameter("@SDCOCO", zDate.SDCOCO),
                //    new SqlParameter("@SDHCHC", zDate.SDHCHC),
                //    new SqlParameter("@ls", listNumber),
                //    new SqlParameter("@cs", listCount));


                //var stgco = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "42", mc = "高怠速CO", jyjg = sdtextBox5.Text.Trim(), jybz = sdtextBox10.Text.Trim(), pd = sdCobox2.Text });
                //var stghc = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "41", mc = "高怠速HC", jyjg = sdtextBox6.Text.Trim(), jybz = sdtextBox11.Text.Trim(), pd = sdCobox3.Text });
                //var stgr = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "43", mc = "高怠速R", jyjg = sdtextBox7.Text.Trim(), jybz = sdtextBox12.Text.Trim(), pd = sdCobox4.Text });
                //var stco = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "45", mc = "怠速CO", jyjg = sdtextBox8.Text.Trim(), jybz = sdtextBox13.Text.Trim(), pd = sdCobox5.Text });
                //var sthc = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "44", mc = "怠速HC", jyjg = sdtextBox9.Text.Trim(), jybz = sdtextBox14.Text.Trim(), pd = sdCobox6.Text });

                //if (sj > 0)
                //{
                //    liststr += "数据录入成功";
                //}
                //if (stgco > 0)
                //{
                //    liststr += ",判定高怠速CO成功";
                //}
                //if (stghc > 0)
                //{
                //    liststr += ",判定高怠速HC成功";
                //}
                //if (stgr > 0)
                //{
                //    liststr += ",判定高怠速R成功";
                //}
                //if (stco > 0)
                //{
                //    liststr += ",判定怠速CO成功";
                //}
                //if (sthc > 0)
                //{
                //    liststr += ",判定怠速HC成功";
                //}
                //listBox1.Items.Add(liststr);
                //initForm();
                #endregion

                #region 双怠速信息录入
                //清除Z_JYBG表里对应的相关数据
                //DeleteJYBG(listNumber, 41, 45);
                //DeleteJYBG(listNumber, 52, 55);
                //DeleteJYBG(listNumber, 56, 56);
                //DeleteJYBG(listNumber, 58, 61);
                //拿到双怠速输入的值
                Z_veh_data zDate = new Z_veh_data();
                if (decideTxt(sdtextBox5.Text.Trim()) == null)
                {
                    zDate.SDCO = null;
                }
                else
                {
                    zDate.SDCO = float.Parse(decideTxt(sdtextBox5.Text.Trim()));
                }
                if (decideTxt(sdtextBox6.Text.Trim()) == null)
                {
                    zDate.SDHC = null;
                }
                else
                {
                    zDate.SDHC = float.Parse(decideTxt(sdtextBox6.Text.Trim()));
                }
                if (decideTxt(sdtextBox7.Text.Trim()) == null)
                {
                    zDate.SDRo = null;
                }
                else
                {
                    zDate.SDRo = float.Parse(decideTxt(sdtextBox7.Text.Trim()));
                }
                if (decideTxt(sdtextBox8.Text.Trim()) == null)
                {
                    zDate.SDCOCO = null;
                }
                else
                {
                    zDate.SDCOCO = float.Parse(decideTxt(sdtextBox8.Text.Trim()));
                }
                if (decideTxt(sdtextBox9.Text.Trim()) == null)
                {
                    zDate.SDHCHC = null;
                }
                else
                {
                    zDate.SDHCHC = float.Parse(decideTxt(sdtextBox9.Text.Trim()));
                }
                //录入数据(表Z_veh_data)
                //new SqlParameter("@height",SqlDbType.Int){value=height==null?DBNull.Value:(object)height}
                var sj = SqlHelper.ExecuteNonQuery("update [Veh_Comprehensive].[dbo].[Z_veh_data]set[排放性双怠速高怠速CO] =@SDCO,[排放性双怠速高怠速HC] =@SDHC,[排放性双怠速高怠速λ] =@SDRo,[排放性双怠速低怠速CO] =@SDCOCO,[排放性双怠速低怠速HC] =@SDHCHC,[排放性简易瞬态工况CO] =null,[排放性简易瞬态工况HC] =null,[排放性简易瞬态工况NO] =null,[排放性简易瞬态工况HCNO] =null,[排放性自由加速法光吸收系数1] =null,[排放性自由加速法光吸收系数2] =null,[排放性自由加速法光吸收系数3] =null,[排放性自由加速法光吸收系数平均] =null,[排放性加载减速工况光吸收系数100] =null,[排放性加载减速工况光吸收系数90] =null,[排放性加载减速工况光吸收系数80] =null,[排放性加载减速工况实测最大轮边功率] =null where[流水号] =@ls and[检验次数] = @cs",
                    new SqlParameter("@SDCO", SqlDbType.Float) { Value= zDate.SDCO ==null?DBNull.Value:(object)zDate.SDCO},
                    new SqlParameter("@SDHC", SqlDbType.Float) { Value = zDate.SDHC == null ? DBNull.Value : (object)zDate.SDHC },
                    new SqlParameter("@SDRo", SqlDbType.Float) { Value = zDate.SDRo == null ? DBNull.Value : (object)zDate.SDRo }, 
                    new SqlParameter("@SDCOCO", SqlDbType.Float) { Value = zDate.SDCOCO == null ? DBNull.Value : (object)zDate.SDCOCO },
                    new SqlParameter("@SDHCHC", SqlDbType.Float) { Value = zDate.SDHCHC == null ? DBNull.Value : (object)zDate.SDHCHC },
                    new SqlParameter("@ls", listNumber),
                    new SqlParameter("@cs", listCount));
                if (sj > 0)
                {
                    liststr += "数据录入成功";
                }

                //判定录入的字段是否为空如果为空则不录入该条数据
                if (decideTxt(sdtextBox6.Text.Trim()) != null)
                {
                    var stghc = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "41", mc = "高怠速HC(10-6)", jyjg = sdtextBox6.Text.Trim(), jybz = sdtextBox11.Text.Trim(), pd = sdCobox3.Text });
                    if (stghc > 0)
                    {
                        liststr += ",判定高怠速HC成功";
                    }
                    else
                    {
                        liststr += ",判定高怠速HC失败";
                    }
                }
                if (decideTxt(sdtextBox5.Text.Trim()) != null)
                {
                    var stgco = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "42", mc = "高怠速CO(%)", jyjg = sdtextBox5.Text.Trim(), jybz = sdtextBox10.Text.Trim(), pd = sdCobox2.Text });
                    if (stgco > 0)
                    {
                        liststr += ",判定高怠速CO成功";
                    }
                    else
                    {
                        liststr += ",判定高怠速CO失败";
                    }
                }
               
                if (decideTxt(sdtextBox7.Text.Trim()) != null)
                {
                    var stgr = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "43", mc = "高怠速λ", jyjg = sdtextBox7.Text.Trim(), jybz = sdtextBox12.Text.Trim(), pd = sdCobox4.Text });
                    if (stgr > 0)
                    {
                        liststr += ",判定高怠速λ成功";
                    }
                    else
                    {
                        liststr += ",判定高怠速λ失败";
                    }
                }
                if (decideTxt(sdtextBox9.Text.Trim()) != null)
                {
                    var sthc = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "44", mc = "怠速HC(10-6)", jyjg = sdtextBox9.Text.Trim(), jybz = sdtextBox14.Text.Trim(), pd = sdCobox6.Text });
                    if (sthc > 0)
                    {
                        liststr += ",判定怠速HC成功";
                    }
                    else
                    {
                        liststr += ",判定怠速HC失败";
                    }
                }
                if (decideTxt(sdtextBox8.Text.Trim()) != null)
                {
                    var stco = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "45", mc = "怠速CO(%)", jyjg = sdtextBox8.Text.Trim(), jybz = sdtextBox13.Text.Trim(), pd = sdCobox5.Text });
                    if (stco > 0)
                    {
                        liststr += ",判定怠速CO成功";
                    }
                    else
                    {
                        liststr += ",判定怠速CO失败";
                    }
                }
               

                //把消息更新到listBox控件
                listBox1.Items.Add(liststr);
                initForm();
                //获取流水号和检验次数加载到控件
                textBox2.Text = listNumber;
                textBox4.Text = listCount.ToString();
                #endregion

            }
            else if (gasType == "简易瞬态")
            {
                #region 简易瞬态信息录入
                //清除Z_JYBG表里对应的相关数据
                //DeleteJYBG(listNumber, 41, 45);
                //DeleteJYBG(listNumber, 52, 55);
                //DeleteJYBG(listNumber, 56, 56);
                //DeleteJYBG(listNumber, 58, 61);
                //拿到简易瞬态输入的值
                Z_veh_data zDate = new Z_veh_data();
                if (decideTxt(jytextBox24.Text.Trim()) == null)
                {
                    zDate.JYCO = null;
                }
                else
                {
                    zDate.JYCO = float.Parse(decideTxt(jytextBox24.Text.Trim()));
                }
                if (decideTxt(jytextBox23.Text.Trim()) == null)
                {
                    zDate.JYHC = null;
                }
                else
                {
                    zDate.JYHC = float.Parse(decideTxt(jytextBox23.Text.Trim()));
                }
                if (decideTxt(jytextBox22.Text.Trim()) == null)
                {
                    zDate.JYNO = null;
                }
                else
                {
                    zDate.JYNO = float.Parse(decideTxt(jytextBox22.Text.Trim()));
                }
                if (decideTxt(jytextBox21.Text.Trim()) == null)
                {
                    zDate.JYHCNO = null;
                }
                else
                {
                    zDate.JYHCNO = float.Parse(decideTxt(jytextBox21.Text.Trim()));
                }
                //录入数据(表Z_veh_data)
                var sj = SqlHelper.ExecuteNonQuery("update [Veh_Comprehensive].[dbo].[Z_veh_data]set[排放性双怠速高怠速CO] =null,[排放性双怠速高怠速HC] =null,[排放性双怠速高怠速λ] =null,[排放性双怠速低怠速CO] =null,[排放性双怠速低怠速HC] =null,[排放性简易瞬态工况CO] =@JYCO,[排放性简易瞬态工况HC] =@JYHC,[排放性简易瞬态工况NO] =@JYNO,[排放性简易瞬态工况HCNO] =@JYHCNO,[排放性自由加速法光吸收系数1] =null,[排放性自由加速法光吸收系数2] =null,[排放性自由加速法光吸收系数3] =null,[排放性自由加速法光吸收系数平均] =null,[排放性加载减速工况光吸收系数100] =null,[排放性加载减速工况光吸收系数90] =null,[排放性加载减速工况光吸收系数80] =null,[排放性加载减速工况实测最大轮边功率] =null where[流水号] =@ls and[检验次数] = @cs",
                    new SqlParameter("@JYCO", SqlDbType.Float) { Value = zDate.JYCO == null ? DBNull.Value : (object)zDate.JYCO },
                    new SqlParameter("@JYHC", SqlDbType.Float) { Value = zDate.JYHC == null ? DBNull.Value : (object)zDate.JYHC },
                    new SqlParameter("@JYNO", SqlDbType.Float) { Value = zDate.JYNO == null ? DBNull.Value : (object)zDate.JYNO },
                    new SqlParameter("@JYHCNO", SqlDbType.Float) { Value = zDate.JYHCNO == null ? DBNull.Value : (object)zDate.JYHCNO },
                    new SqlParameter("@ls", listNumber),
                    new SqlParameter("@cs", listCount));
                if (sj > 0)
                {
                    liststr += "数据录入成功";
                }

                //判定录入的字段是否为空如果为空则不录入该条数据
                if (decideTxt(jytextBox24.Text.Trim()) != null)
                {
                    var jyco = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "52", mc = "简易瞬态工况CO(g/km)", jyjg = jytextBox24.Text.Trim(), jybz = jytextBox19.Text.Trim(), pd = jyCobox7.Text });
                    if (jyco > 0)
                    {
                        liststr += ",判定简易瞬态工况CO成功";
                    }
                    else
                    {
                        liststr += ",判定简易瞬态工况CO失败";
                    }
                }
                if (decideTxt(jytextBox23.Text.Trim()) != null)
                {
                    var jyhc = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "53", mc = "简易瞬态工况HC(g/km)", jyjg = jytextBox23.Text.Trim(), jybz = jytextBox18.Text.Trim(), pd = jyCobox8.Text });
                    if (jyhc > 0)
                    {
                        liststr += ",判定简易瞬态工况HC成功";
                    }
                    else
                    {
                        liststr += ",判定简易瞬态工况HC失败";
                    }
                }
                if (decideTxt(jytextBox22.Text.Trim()) != null)
                {
                    var jyno = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "54", mc = "简易瞬态工况NO(g/km)", jyjg = jytextBox22.Text.Trim(), jybz = jytextBox17.Text.Trim(), pd = jyCobox9.Text });
                    if (jyno > 0)
                    {
                        liststr += ",判定简易瞬态工况NO成功";
                    }
                    else
                    {
                        liststr += ",判定简易瞬态工况NO失败";
                    }
                }
                if (decideTxt(jytextBox21.Text.Trim()) != null)
                {
                    var jyhcno = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "55", mc = "简易瞬态工况HC+NO(g/km)", jyjg = jytextBox21.Text.Trim(), jybz = jytextBox16.Text.Trim(), pd = jyCobox10.Text });
                    if (jyhcno > 0)
                    {
                        liststr += ",判定简易瞬态工况HCNO成功";
                    }
                    else
                    {
                        liststr += ",判定简易瞬态工况HCNO失败";
                    }
                }
                //把信息更新到listBox控件
                listBox1.Items.Add(liststr);
                initForm();
                //获取流水号和检验次数加载到控件
                textBox2.Text = listNumber;
                textBox4.Text = listCount.ToString();
                #endregion
            } else if (gasType == "自由加速")
            {
                #region 自由加速信息录入
                //清除Z_JYBG表里对应的相关数据
                //DeleteJYBG(listNumber, 41, 45);
                //DeleteJYBG(listNumber, 52, 55);
                //DeleteJYBG(listNumber, 56, 56);
                //DeleteJYBG(listNumber, 58, 61);
                //拿到自由加速输入的值
                Z_veh_data zDate = new Z_veh_data();
                if (decideTxt(uptextBox15.Text.Trim()) == null)
                {
                    zDate.upRay1 = null;
                }
                else
                {
                    zDate.upRay1 = float.Parse(decideTxt(uptextBox15.Text.Trim()));
                }
                if (decideTxt(uptextBox20.Text.Trim()) == null)
                {
                    zDate.upRay2 = null;
                }
                else
                {
                    zDate.upRay2 = float.Parse(decideTxt(uptextBox20.Text.Trim()));
                }
                if (decideTxt(uptextBox25.Text.Trim()) == null)
                {
                    zDate.upRay3 = null;
                }
                else
                {
                    zDate.upRay3 = float.Parse(decideTxt(uptextBox25.Text.Trim()));
                }
                if (decideTxt(uptextBox26.Text.Trim()) == null)
                {
                    zDate.upRayaverage = null;
                }
                else
                {
                    zDate.upRayaverage = float.Parse(decideTxt(uptextBox26.Text.Trim()));
                }
                //录入数据(表Z_veh_data)
                var sj = SqlHelper.ExecuteNonQuery("update [Veh_Comprehensive].[dbo].[Z_veh_data]set[排放性双怠速高怠速CO] =null,[排放性双怠速高怠速HC] =null,[排放性双怠速高怠速λ] =null,[排放性双怠速低怠速CO] =null,[排放性双怠速低怠速HC] =null,[排放性简易瞬态工况CO] =null,[排放性简易瞬态工况HC] =null,[排放性简易瞬态工况NO] =null,[排放性简易瞬态工况HCNO] =null,[排放性自由加速法光吸收系数1] =@upRay1,[排放性自由加速法光吸收系数2] =@upRay2,[排放性自由加速法光吸收系数3] =@upRay3,[排放性自由加速法光吸收系数平均] =@upRayaverage,[排放性加载减速工况光吸收系数100] =null,[排放性加载减速工况光吸收系数90] =null,[排放性加载减速工况光吸收系数80] =null,[排放性加载减速工况实测最大轮边功率] =null where[流水号] =@ls and[检验次数] = @cs",
                    new SqlParameter("@upRay1", SqlDbType.Float) { Value = zDate.upRay1 == null ? DBNull.Value : (object)zDate.upRay1 },
                    new SqlParameter("@upRay2", SqlDbType.Float) { Value = zDate.upRay2 == null ? DBNull.Value : (object)zDate.upRay2 },
                    new SqlParameter("@upRay3", SqlDbType.Float) { Value = zDate.upRay3 == null ? DBNull.Value : (object)zDate.upRay3 },
                    new SqlParameter("@upRayaverage", SqlDbType.Float) { Value = zDate.upRayaverage == null ? DBNull.Value : (object)zDate.upRayaverage },
                    new SqlParameter("@ls", listNumber),
                    new SqlParameter("@cs", listCount));
                if (sj > 0)
                {
                    liststr += "数据录入成功";
                }

                

                if (decideTxt(uptextBox26.Text.Trim()) != null)
                {
                    var upray = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "56", mc = "光吸收系数(m-1)", jyjg = uptextBox26.Text.Trim(), jybz = uptextBox27.Text.Trim(), pd = upCobox11.Text });
                    if (upray > 0)
                    {
                        liststr += ",判定光吸收系数成功";
                    }
                    else
                    {
                        liststr += ",判定光吸收系数失败";
                    }
                }

                //把信息更新到listBox控件
                listBox1.Items.Add(liststr);
                initForm();
                //获取流水号和检验次数加载到控件
                textBox2.Text = listNumber;
                textBox4.Text = listCount.ToString();
                #endregion
            } else if (gasType == "加载减速")
            {
                #region 加载减速光吸收系数信息录入
                //清除Z_JYBG表里对应的相关数据
                //DeleteJYBG(listNumber, 41, 45);
                //DeleteJYBG(listNumber, 52, 55);
                //DeleteJYBG(listNumber, 56, 56);
                //DeleteJYBG(listNumber, 58, 61);
                //拿到加载减速光吸收系数输入的值
                Z_veh_data zDate = new Z_veh_data();
                if (decideTxt(downtextBox28.Text.Trim()) == null)
                {
                    zDate.downRay1 = null;
                }
                else
                {
                    zDate.downRay1 = float.Parse(decideTxt(downtextBox28.Text.Trim()));
                }
                if (decideTxt(downtextBox29.Text.Trim()) == null)
                {
                    zDate.downRay2 = null;
                }
                else
                {
                    zDate.downRay2 = float.Parse(decideTxt(downtextBox29.Text.Trim()));
                }
                if (decideTxt(downtextBox30.Text.Trim()) == null)
                {
                    zDate.downRay3 = null;
                }
                else
                {
                    zDate.downRay3 = float.Parse(decideTxt(downtextBox30.Text.Trim()));
                }
                if (decideTxt(downtextBox31.Text.Trim()) == null)
                {
                    zDate.downRayaverage = null;
                }
                else
                {
                    zDate.downRayaverage = float.Parse(decideTxt(downtextBox31.Text.Trim()));
                }
                //录入数据(表Z_veh_data)
                var sj = SqlHelper.ExecuteNonQuery("update[Veh_Comprehensive].[dbo].[Z_veh_data]set[排放性双怠速高怠速CO] = null,[排放性双怠速高怠速HC] = null,[排放性双怠速高怠速λ] = null,[排放性双怠速低怠速CO] = null,[排放性双怠速低怠速HC] = null,[排放性简易瞬态工况CO] = null,[排放性简易瞬态工况HC] = null,[排放性简易瞬态工况NO] = null,[排放性简易瞬态工况HCNO] = null,[排放性自由加速法光吸收系数1] = null,[排放性自由加速法光吸收系数2] = null,[排放性自由加速法光吸收系数3] = null,[排放性自由加速法光吸收系数平均] = null,[排放性加载减速工况光吸收系数100] =@downRay1,[排放性加载减速工况光吸收系数90] =@downRay2,[排放性加载减速工况光吸收系数80] =@downRay3,[排放性加载减速工况实测最大轮边功率] =@downRayaverage where[流水号] = @ls and[检验次数] = @cs",
                    new SqlParameter("@downRay1", SqlDbType.Float) { Value = zDate.downRay1 == null ? DBNull.Value : (object)zDate.downRay1 },
                    new SqlParameter("@downRay2", SqlDbType.Float) { Value = zDate.downRay2 == null ? DBNull.Value : (object)zDate.downRay2 },
                    new SqlParameter("@downRay3", SqlDbType.Float) { Value = zDate.downRay3 == null ? DBNull.Value : (object)zDate.downRay3 },
                    new SqlParameter("@downRayaverage", SqlDbType.Float) { Value = zDate.downRayaverage == null ? DBNull.Value : (object)zDate.downRayaverage },
                    new SqlParameter("@ls", listNumber),
                    new SqlParameter("@cs", listCount));
                if (sj > 0)
                {
                    liststr += "数据录入成功";
                }

                
                if (decideTxt(downtextBox28.Text.Trim()) != null)
                {
                    var downray1 = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "58", mc = "加载减速工况100%(m-1)", jyjg = downtextBox28.Text.Trim(), jybz = downtextBox32.Text.Trim(), pd = downCobox12.Text });
                    if (downray1 > 0)
                    {
                        liststr += ",判定加载减速工况100%成功";
                    }
                    else
                    {
                        liststr += ",判定加载减速工况100%失败";
                    }
                }
                if (decideTxt(downtextBox29.Text.Trim()) != null)
                {
                    var downray2 = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "59", mc = "加载减速工况90%(m-1)", jyjg = downtextBox29.Text.Trim(), jybz = downtextBox33.Text.Trim(), pd = downCobox13.Text });
                    if (downray2 > 0)
                    {
                        liststr += ",判定加载减速工况90%成功";
                    }
                    else
                    {
                        liststr += ",判定加载减速工况90%失败";
                    }
                }
                if (decideTxt(downtextBox30.Text.Trim()) != null)
                {
                    var downray3 = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "60", mc = "加载减速工况80%(m-1)", jyjg = downtextBox30.Text.Trim(), jybz = downtextBox34.Text.Trim(), pd = downCobox14.Text });
                    if (downray3 > 0)
                    {
                        liststr += ",判定加载减速工况80%成功";
                    }
                    else
                    {
                        liststr += ",判定加载减速工况80%失败";
                    }
                }
                if (decideTxt(downtextBox31.Text.Trim()) != null)
                {
                    var downray = InsertJYBG(new Z_JYBG() { lsh = listNumber, jycs = listCount, xh = "61", mc = "实测最大轮边功率", jyjg = downtextBox31.Text.Trim(), jybz = downtextBox35.Text.Trim(), pd = downCobox15.Text });
                    if (downray > 0)
                    {
                        liststr += ",判定实测最大轮边功率成功";
                    }
                    else
                    {
                        liststr += ",判定实测最大轮边功率失败";
                    }
                }

                //把信息更新到listBox控件
                listBox1.Items.Add(liststr);
               // initForm();
                //获取流水号和检验次数加载到控件
            //    textBox2.Text = listNumber;
              //  textBox4.Text = listCount.ToString();
                #endregion
            }

            //总判定数据提交
            var zlist = SqlHelper.ExecuteNonQuery("update [Veh_Comprehensive].[dbo].[Z_veh_data]set[排放性汽油车判定] =@zpd,[排放性柴油车判定] =@zpd where[流水号] =@ls and[检验次数] = @cs",
                        new SqlParameter("@zpd", zcomboBox16.Text),
                        new SqlParameter("@ls", listNumber),
                        new SqlParameter("@cs", listCount));
        }

        /// <summary>
        /// 给数据库Z_JYBG做添加
        /// </summary>
        /// <param name="zj"></param>
        /// <returns></returns>
        public int InsertJYBG(Z_JYBG zj)
        {
           return  SqlHelper.ExecuteNonQuery("insert into Z_JYBG(lsh,jycs,xh,mc,jyjg,jybz,pd) values(@lsh,@jycs,@xh,@mc,@jyjg,@jybz,@pd)",
                new SqlParameter("@lsh",zj.lsh),
                new SqlParameter("@jycs", zj.jycs),
                new SqlParameter("@xh", zj.xh),
                new SqlParameter("@mc", zj.mc),
                new SqlParameter("@jyjg", zj.jyjg),
                new SqlParameter("@jybz", zj.jybz),
                new SqlParameter("@pd", zj.pd));
        }

        /// <summary>
        /// 给数据库Z_JYBG做删除
        /// </summary>
        /// <param name="lsh"></param>
        public void DeleteJYBG(string lsh,int small,int big)
        {
            string str = "delete from Z_JYBG where lsh=@ls and xh between "+ small + " and "+ big + "";
            SqlHelper.ExecuteNonQuery(str,new SqlParameter("@ls", lsh));
        }

        //判断文本框里的值不为""
        public string decideTxt(string txt)
        {
            if (txt == "")
            {
                txt = null;
            }

            return txt;
        }
    }
}
